package com.xk.school_device.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xk.school_device.entity.Purchases;
import com.xk.school_device.mapper.PurchasesMapper;
import com.xk.school_device.service.IPurchasesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xk
 * @since 2025-04-16
 */
@Service
public class PurchasesServiceImpl extends ServiceImpl<PurchasesMapper, Purchases> implements IPurchasesService {

    @Autowired
    private PurchasesMapper purchasesMapper;
    @Override
    public PageInfo<Purchases> getPurchases(Purchases purchases) {
        PageHelper.startPage(purchases.getCurrent(),purchases.getSize());
        List<Purchases> purchases1 = purchasesMapper.getPurchases(purchases);
        return new PageInfo<>(purchases1);

    }

    @Override
    public void deleteById(String id) {
        purchasesMapper.deletePurchase(id);
    }

    @Override
    public void updatePurchasesById(Purchases purchases) {
        purchasesMapper.updatePurchasesById(purchases);
    }

    @Override
    public PageInfo<Purchases> findPendingApprovals(String userId,Purchases purchases) {
        PageHelper.startPage(purchases.getCurrent(),purchases.getSize());
        List<Purchases> pendingApprovals = purchasesMapper.findPendingApprovals(purchases);
        return new PageInfo<>(pendingApprovals);
    }

    @Override
    public Purchases getPurchaseById(String purchaseId) {
        return purchasesMapper.getPurchaseById(purchaseId);
    }
}
